/*=============================================================================
Copyright (c) 2010 Crytek Studios. All Rights Reserved.

Revision history:
	* Created by Nicolas Schulz, August 2010

=============================================================================*/

#pragma once 

#ifndef _GPUTIMER_H
#define _GPUTIMER_H

class CSimpleGPUTimer
{
public:
	static void EnableTiming();
	static void DisableTiming();
	static bool IsTimingEnabled() { return s_bTimingEnabled; }
protected:
	static bool s_bTimingEnabled;

public:
	CSimpleGPUTimer();
	~CSimpleGPUTimer();

	void Start();
	void Stop();
	void UpdateTime();

	float GetTime() { return m_time; }
	float GetSmoothedTime() { return m_smoothedTime; }

	bool IsStarted() const { return m_bStarted; }
	bool HasPendingQueries() const { return m_bWaiting; }

//protected:
	void Release();
	bool Init();

	// this easy way of computing the drawcalls only works on PS3




protected:
	float  m_time;
	float  m_smoothedTime;

	bool   m_bInitialized;
	bool   m_bStarted;
	bool   m_bWaiting;

#if defined( WIN32 ) && defined( DIRECT3D9 )
	IDirect3DQuery9 *m_pQueryStart, *m_pQueryStop, *m_pQueryFreq;
#elif (defined( WIN32 ) || defined( gringo )) && defined( DIRECT3D10 )
	ID3D11Query *m_pQueryStart, *m_pQueryStop, *m_pQueryFreq;
#elif defined( XENON )
	IDirect3DPerfCounters9 *m_pPerfCntStart, *m_pPerfCntStop;
#elif defined( PS3 )
	tdResHandle m_dpStart, m_dpStop;
#endif
};

#endif
